﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using System.Text;
using System.Collections;

namespace VSM
{
    public partial class ServiceHistory : System.Web.UI.Page
    {

        private static GeneralFunctions GF = null;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Request.QueryString["VIN"] != null && Request.QueryString["VIN"].Length > 0)
                {
                    Session["HisVIN"] = Request.QueryString["VIN"];
                    txt_VIN.Text = Session["HisVIN"].ToString();
                    loadData();
                }
            }
        }

        protected void btn_Filter_Click(object sender, EventArgs e)
        {
            loadData();
        }

        private void loadData()
        {

            string sql = " select ROW_NUMBER() OVER (ORDER BY GeneralID) AS No, GeneralID, gs.JobID, gs.Receptionist, gs.AdviserCode, gs.TechnicianCode, jk.Name as JobKindName, pm.Name as PaymentMethod, ";
            sql += " gs.DateIn, gs.TimeIn, gs.ExpDelivery, gs.ExpTime, gs.StartDate, gs.StartTime, ";
            sql += " gs.VehicleCode, gs.VIN, gs.CustomerCode, ";
            sql += " adv.Name AdviserName, tec.Name TechnicianName, ";
            sql += " gs.FinishDate, gs.FinishTime, gs.ActualDelivery, gs.ActualDeliveryTime, gs.CustomerRequest, gs.Notice, ";
            sql += " gs.Odometer, gs.ServiceDate, gs.JobKind, ";
            sql += " gs.VehicleName, gs.Brand, gs.EngineNo, gs.RegNo, gs.Model, gs.ColorCode, gs.CustomerName, gs.OtherName, ";
            sql += " gs.Address, gs.Tel, gs.TaxCode, gs.ContactPerson, gs.ContactPhone, gs.Mobile, gs.Payment ";
            sql += " from U_GeneralService gs ";
            sql += " left join VSM_ORG..[@JOBKINDSVC] jk on jk.Code = gs.JobKind";
            sql += " left join VSM_ORG..[@PAYMENTMETHODSVC] pm on pm.Code = gs.Payment ";
            sql += " left join VSM_ORG..[@TECHNICIAN] adv on gs.AdviserCode = adv.Code ";
            sql += " left join VSM_ORG..[@TECHNICIAN] tec on gs.TechnicianCode = tec.Code ";
            sql += " where gs.VIN = '" + Session["HisVIN"].ToString() + "'";

            Services sv = new Services();
            DataTable dt = sv.ExecuteQuery("DEALER", sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];

                txt_VIN.Text = dr["VIN"].ToString();
                txt_Brand.Text = dr["Brand"].ToString();
                txt_VehicleName.Text = dr["VehicleName"].ToString();
                txt_EngineNo.Text = dr["EngineNo"].ToString();
                txt_RegNo.Text = dr["RegNo"].ToString();
                txt_Model.Text = dr["Model"].ToString();

                txt_CusName.Text = dr["CustomerName"].ToString();
                txt_OtherName.Text = dr["OtherName"].ToString();
                txt_Address.Text = dr["Address"].ToString();
                txt_Tel.Text = dr["Tel"].ToString();
                txt_Mobile.Text = dr["Mobile"].ToString();
                txt_TaxCode.Text = dr["TaxCode"].ToString();
                txt_ContactPerson.Text = dr["ContactPerson"].ToString();
                txt_PhoneContact.Text = dr["ContactPhone"].ToString();

                grvPO.DataSource = dt;
                grvPO.DataBind();

            }

        }

    }
}